using UnityEngine;

namespace ActorSystem
{
    public class DurationDamageBuff : NormalBuffBase
    {
        public int Health = 20; //这里是减血
        public int Damage = 20; //还能减你伤害
        public float MoveSpeed = 6f; //减你移动速度
        public float AttackSpeed = 1f; //减你攻击速度
        public float Duration { get; set; }
        private float timeout;

        public override void OnTrigger()
        {
            var property = Target.Property;
            property.Health -= Health;
            property.Damage -= Damage;
            property.AttackSpeed -= AttackSpeed;
            property.MoveSpeed -= MoveSpeed;
            timeout = Time.time + Duration;
        }

        public void OnTriggerExit()
        {
            var property = Target.Property;
            property.Damage += Damage;
            property.AttackSpeed += AttackSpeed;
            property.MoveSpeed += MoveSpeed;
        }

        public override bool OnUpdate()
        {
            if (Time.time > timeout)
            {
                OnTriggerExit();
                return false;
            }
            return true;
        }
    }
}